package com.bifrost.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.validator.constraints.Range;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.Min;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


/**
 * The persistent class for the CUSTOMER_TYPE database table.
 */
@Entity
@Table(name = "CUSTOMER_TYPE",indexes = {
        @Index(name = "TYPE_CODE_MERCHANT_INDEX",columnList = "TYPE_CODE,MERCHANT_ID",unique = true)
})
@NamedQuery(name = "CustomerType.findAll", query = "SELECT c FROM CustomerType c")
public class CustomerType implements Serializable {
    private static final long serialVersionUID = 1L;
    public static final String  DEFAULT_TYPE_CODE = "DEFAULT";
    public static final String  DEFAULT_TYPE_NAME = "普通会员";

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "CUSTOMER_TYPE_ID", unique = true, nullable = false)
    private Long customerTypeId;

    /**
     * 会员须知
     * */
    @Column( name = "DESCRIPTION")
    @Lob
    private String description;

    @Column(length = 128, name = "NAME")
    private String name;

    @Column(name = "TYPE_CODE", length = 32,nullable = false)
    private String typeCode;

    @Column(name = "UPDATED_BY", length = 64)
    @JsonIgnore
    private String updatedBy;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "UPDATED_TIMESTAMP")
    @JsonIgnore
    private Date updatedTimestamp = new Date();

    /**
     * 会员卡配置信息：如logo，背景图片background等
     * */
    @Column( name = "CONFIG")
    @Lob
    private String config;

    @Column( name = "IS_SHIPPING_FREE")
    private Boolean shippingFree = Boolean.FALSE;

    @Column( name = "DISCOUNT_RATIO")
   @Range(min = 0,max = 10,message = "折扣必须大于0并且小于10")
    private Double discountRatio=1.0;

    @Column( name = "BONUS_POINTS_RATIO")
    private Double bonusPointsRatio=1.0;

    @Column(name = "GROWTH_VALUE")
    private Integer growthValue=0;

    @Column( name = "MERCHANT_ID",nullable = false)
    private Long merchantId;
    @Column(name = "BACKGROUND")
    private String background;
    @Column(name = "LOGO")
    private String logo;
    //bi-direc
    // tional many-to-one association to Customer
    @OneToMany(mappedBy = "customerType")
    @JsonIgnore
    @org.hibernate.annotations.ForeignKey(name = "none")
    private List<Customer> customers;

    public CustomerType() {
    }

    public CustomerType(Long  customerTypeId,String name,String description,  String typeCode) {
        this.customerTypeId=customerTypeId;
        this.description = description;
        this.name = name;
        this.typeCode = typeCode;
    }

    public Long getCustomerTypeId() {
        return this.customerTypeId;
    }

    public void setCustomerTypeId(Long customerTypeId) {
        this.customerTypeId = customerTypeId;
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getTypeCode() {
        return this.typeCode;
    }

    public void setTypeCode(String typeCode) {
        this.typeCode = typeCode;
    }

    public String getUpdatedBy() {
        return this.updatedBy;
    }

    public void setUpdatedBy(String updatedBy) {
        this.updatedBy = updatedBy;
    }

    public Date getUpdatedTimestamp() {
        return this.updatedTimestamp;
    }

    public void setUpdatedTimestamp(Date updatedTimestamp) {
        this.updatedTimestamp = updatedTimestamp;
    }

    public List<Customer> getCustomers() {
        return this.customers;
    }

    public void setCustomers(List<Customer> customers) {
        this.customers = customers;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getConfig() {
        return config;
    }

    public void setConfig(String config) {
        this.config = config;
    }

    public Boolean isShippingFree() {
        return shippingFree;
    }

    public void setShippingFree(Boolean shippingFree) {
        this.shippingFree = shippingFree;
    }

    public Double getDiscountRatio() {
        return discountRatio;
    }

    public void setDiscountRatio(Double discountRatio) {
        this.discountRatio = discountRatio;
    }

    public Double getBonusPointsRatio() {
        return bonusPointsRatio;
    }

    public void setBonusPointsRatio(Double bonusPointsRatio) {
        this.bonusPointsRatio = bonusPointsRatio;
    }

    public Integer getGrowthValue() {
        return growthValue;
    }

    public void setGrowthValue(Integer growthValue) {
        this.growthValue = growthValue;
    }

    public Long getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(Long merchantId) {
        this.merchantId = merchantId;
    }

    public String getBackground() {
        return background;
    }

    public void setBackground(String background) {
        this.background = background;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }
}